﻿using ERPEF.Model;
using ERPIService;
using Microsoft.EntityFrameworkCore;
using S4Project;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ERPService
{
     public class bs_Model_FromService: bs_Model_FromIService
    {
        private readonly MyDbContext myDbContext;
        public bs_Model_FromService(MyDbContext myDbContext)
        {
            this.myDbContext = myDbContext;
        }
        //查询
        public async Task<List<bs_Model_From>> Query()
        {
            return await myDbContext.bs_Model_From.Where(c => c.IsDeleted == false).ToListAsync();
        }

        //添加
        public async Task<int> Add(bs_Model_From bs_Model_From)
        {
            //myDbContext.Add("SET IDENTITY_INSERT dbo.bs_Model_From ON");
            myDbContext.bs_Model_From.Add(bs_Model_From);
            //myDbContext.Add("SET IDENTITY_INSERT dbo.bs_Model_From   ON");
            return await myDbContext.SaveChangesAsync();
        }
        //逻辑删除
        public async Task<int> Delete(int model_from_id)
        {
            var del = myDbContext.bs_Model_From.Find(model_from_id);
            if (del != null)
            {
                del.IsDeleted = true;
                await myDbContext.SaveChangesAsync();
                return 1;
            }
            return 0;
        }

        //查询单个字典
        public async Task<List<bs_dict_image>> DictQuery()
        {
            return await myDbContext.bs_dict_image.Where(c => c.IsDeleted == false).ToListAsync();
        }

        public async Task<int> UpdateModel(bs_Model_From bs_Model_From)
        {
            myDbContext.bs_Model_From.Update(bs_Model_From);
            return await myDbContext.SaveChangesAsync();
        }
    }
}
